<report title="D2D- EMR Data Quality Smoking Status Report v1" description="Displays number and % of patients with smoking status identified in measurements" active="1">
   
<query> 

select
count(distinct d2.demographic_no) as "All Patients >= 12",
count(distinct d.demographic_no) as "Smoking Status Identified",
(count(distinct d.demographic_no)/count(distinct d2.demographic_no))*100 as "Percentage"

from 
demographic d, demographic d2
where floor(datediff(curdate(),str_to_date(concat(d.year_of_birth,d.month_of_birth,d.date_of_birth),'%Y%m%d'))/365.25) >="12"

and (datediff(curdate(),str_to_date(concat(d2.year_of_birth,d2.month_of_birth,d2.date_of_birth),'%Y%m%d'))/365.25) >="12"

and d.patient_status = "AC" 
and d2.patient_status = "AC" 

and d.demographic_no in
(select m.demographicNo from measurements m
WHERE  m.demographicNo =d.demographic_no 
AND m.type in ('SMK','SKST','HFMS','Smks')
group by m.demographicNo)


</query>


</report>